//
//  HomeTopCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/23.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDCycleScrollView


class HomeTopCell: BaseTableViewCell {

    @IBOutlet weak var bottomConstr: NSLayoutConstraint!
    
    lazy var cycleScrollView : SDCycleScrollView = {
        
        let temp = SDCycleScrollView(frame:CGRect(x: 0, y: 0, width: KScreenW, height: KScreenW / 8 * 3) , delegate: self, placeholderImage: UIImage(named: "placeholder"))
        
        temp?.autoScrollTimeInterval = 3
        
        temp?.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated
        
        return temp!
        
    }()
    
    var items : [HomeItemModel]?{
    
        didSet{
            
            if items != nil{
                
                var arry = [String]()
                
                for item in items! {
//                    QL1(item.image)

                    arry.append(item.image)
                }
                
                
                self.cycleScrollView.imageURLStringsGroup = arry

            }
            
            
        
        }
    
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        bottomConstr.constant = -8
        contentView.addSubview(cycleScrollView)
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    
    
    }
    
    
      }




extension HomeTopCell: SDCycleScrollViewDelegate{

    /** 点击图片回调 */
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int){
    
        let type = items?[index].type
        
        let data = items?[index].data
        
        if type == "keyword" {
            
            let temp = GoodsListController()
            
            temp.keyword = data
            
            viewController().navigationController?.pushViewController(temp, animated: true)
            
        } else {
            
            if type == "url" {
                
                if items![index].data.contains("mall.xjscvip.com") {
                    
                    let temp = UpLoadIconController()
                    
                    
                    temp.urlStr = data ?? ""
                    
                    
                    viewController().navigationController?.pushViewController(temp, animated: true)
                    
                } else {
                    
                    let temp = UpLoadIconController()
                    
                    temp.hiddenBar = false
                    
                    temp.urlStr = data ?? ""
                    
                    
                    viewController().navigationController?.pushViewController(temp, animated: true)
                    
                }
                
                
                
            } else if type == "goods"{
                
                let temp = GoodsDetailController()
                
                temp.urlStr = data ?? ""
                
                viewController().navigationController?.pushViewController(temp, animated: true)
                
            }
            
            
            
        }
    
    }
    
    
    /** 图片滚动回调 */
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didScrollTo index: Int){
    
    
    }
    
    
    
    
    




}
